﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Weazel.Willows.PreliminaryModel
{
	public class State
		: PreliminaryItemBase
	{
		private bool isInitial;
		public bool IsInitial
		{
			get { return isInitial; }
		}

		public State(Model model, Module parent, XmlElement xmlElement)			
			: base(model)
		{
			read(xmlElement);
		}

		#region Read from XML
		private void read(XmlElement description)
		{
			System.Diagnostics.Debug.Assert(description.Name == "State");
			System.Diagnostics.Debug.Assert(description.HasAttribute("name"));

			this.Name = description.Attributes["name"].Value;

			if (description.HasAttribute("initial"))
				this.isInitial = bool.Parse(description.Attributes["initial"].Value);
			else
				this.isInitial = false;
		}
		#endregion

		public void ExpandTo(Weazel.Willows.Model.Module module)
		{
			Weazel.Willows.Model.State state =
				new Weazel.Willows.Model.State(module, Name, isInitial);

			module.States.Add(Name, state);
		}
	}
}
